package com.yanqu.road.utils.net;

import com.yanqu.road.utils.ServerType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 网络配置
 */
public class ChannelNetConfigHelper {

    private static Logger logger = LogManager.getLogger(ChannelNetConfigHelper.class.getName());

    private static Map<Integer, ServerNetConfig> channelMap = new HashMap<>();

    public static boolean init(Map<String, List<ServerNetConfig>> netConfigMap) {
        try {
            List<ServerNetConfig> channelConfigList = netConfigMap.get("channel_server");
            if(null != channelConfigList){
                for(ServerNetConfig netConfig : channelConfigList){
                    channelMap.put(netConfig.getServerIndex(), netConfig);
                }
            }
        } catch (Exception e) {
            logger.error("channelServer error", e);
            return false;
        }
        return true;
    }

    /**
     * 服务器配置
     */
    public static ServerNetConfig getNetConfigXml(int serverType, int serverIndex) {
        ServerNetConfig xml = null;
        switch (serverType) {
            case ServerType.SERVER_CHANNEL:
                xml = channelMap.get(serverIndex);
                break;
        }
        return xml;
    }
}
